﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ResxCrunch
{
    /// <summary>
    /// Add filter form
    /// </summary>
    public partial class FrmAddFilter : Form
    {
        /// <summary>
        /// Gets or sets the filter value.
        /// </summary>
        /// <value>The filter value.</value>
        public string FilterValue { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="FrmAddFilter"/> class.
        /// </summary>
        public FrmAddFilter()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Handles the Click event of the btnCancel control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        /// <summary>
        /// Handles the Click event of the btnAdd control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnAdd_Click(object sender, EventArgs e)
        {
            bool errorsPresent = false;

            if (txtNewFilter.Text.Length == 0)
            {
                errorProviderFilter.SetError(txtNewFilter, "Filter cannot have an empty value");
                errorsPresent = true;
            }
            else
            {
                errorProviderFilter.SetError(txtNewFilter, string.Empty);
            }

            if (!errorsPresent)
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }

        /// <summary>
        /// Handles the Load event of the FrmAddFilter control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void FrmAddFilter_Load(object sender, EventArgs e)
        {
            txtNewFilter.DataBindings.Add("Text", this, "FilterValue");
            txtNewFilter.Focus();
        }
    }
}
